import { RectNode, RectNodeModel, h } from '@logicflow/core';
import PropSetting from './PropSetting.vue';
import { NodeTypeEnum } from '../enums';
import { HisProcinstOpState, ProcinstTaskStatus } from '@/views/flow/enums';

class UserTaskModel extends RectNodeModel {
    initNodeData(data: any) {
        super.initNodeData(data);
        this.width = 100;
        this.height = 60;
        this.radius = 5;
    }

    getNodeStyle() {
        const style = super.getNodeStyle();
        const properties = this.properties;

        const opLog: any = properties.opLog;
        if (!opLog) {
            return style;
        }

        if (opLog.state == HisProcinstOpState.Completed.value && opLog.extra) {
            if (opLog.extra.approvalResult == ProcinstTaskStatus.Pass.value) {
                style.stroke = 'green';
            } else {
                style.stroke = 'red';
            }
        } else if (opLog.state == HisProcinstOpState.Failed.value) {
            style.stroke = 'red';
        } else {
            style.stroke = 'rgb(24, 125, 255)';
        }

        return style;
    }
}

class UserTaskView extends RectNode {
    // 获取标签形状的方法，用于在节点中添加一个自定义的 SVG 元素
    getShape() {
        // 获取XxxNodeModel中定义的形状属性
        const { model } = this.props;
        console.log(model.properties);
        const { x, y, width, height, radius } = model;
        // 获取XxxNodeModel中定义的样式属性
        const style = model.getNodeStyle();

        return h('g', {}, [
            h('rect', {
                ...style,
                x: x - width / 2,
                y: y - height / 2,
                width,
                height,
                rx: radius,
                ry: radius,
            }),
            h(
                'svg',
                {
                    x: x - width / 2,
                    y: y - height / 2,
                    width: 20,
                    height: 20,
                    viewBox: '0 0 1024 1024',
                },
                [
                    h('path', {
                        fill: style.stroke,
                        d: 'M507.776 186.88c-90.765824 0-155.697664 69.77536-155.879936 149.255168v0.045056c0.005632 24.035328 6.509568 49.40288 16.67072 72.282624 7.33696 16.520704 16.459264 31.709184 27.575296 43.876352-66.06336 22.601216-143.458816 59.79904-182.578176 133.147648L211.456 589.44V826.88h592.64v-237.44l-2.107904-3.95264c-38.556672-72.2944-114.277888-109.44-179.70176-132.135424 31.938048-32.477696 41.35936-74.396672 41.3696-117.171712v-0.045056C663.473664 256.65536 598.541824 186.88 507.776 186.88zM445.803008 271.513088c4.195328 0.01024 8.801792 0.150528 13.88032 0.450048 40.459264 2.384384 54.076416 9.667584 64.543744 16.574976 10.466816 6.90688 17.84576 13.482496 45.508096 14.288896h0.017408c21.555712-0.8064 31.922688-4.649472 39.356928-9.003008 3.012608-1.76384 5.541888-3.597824 8.134144-5.348864 6.85056 14.685184 10.530304 30.919168 10.571776 47.719936-0.014336 47.84128-8.239104 81.344512-52.105216 108.761088l4.291072 32.34304c9.130496 2.77248 18.568192 5.814784 28.1472 9.150976 1.337856 5.5808 2.883584 12.900352 3.922944 20.681728 1.089024 8.152576 1.517568 16.634368 0.845824 23.003136-0.671232 6.368768-2.648576 9.806848-2.995712 10.153984-22.296064 22.296064-61.873664 35.298816-102.017024 35.298816-40.143872 0-79.72096-13.002752-102.017024-35.298816-0.347136-0.347136-2.32448-3.785216-2.996224-10.153984-0.671232-6.368768-0.2432-14.85056 0.846336-23.003136 1.044992-7.824384 2.603008-15.186944 3.945984-20.779008 9.483264-3.29728 18.82624-6.30784 27.86816-9.053696l2.55744-34.656256c-2.082816-2.671104-4.205056-4.440576-6.73792-6.34112-9.789952-7.34464-21.66272-23.502336-30.04928-42.38592-8.382976-18.876416-13.576704-40.45312-13.584384-57.724928 0.051712-20.707328 5.62432-40.556032 15.859712-57.700864 1.831424-0.681984 3.762688-1.402368 5.933056-2.116096 7.632896-2.510336 18.092544-4.906496 36.273152-4.860928zM368.312832 501.68576c-0.032256 0.23552-0.068096 0.464384-0.09984 0.700416-1.324544 9.913856-2.102784 20.70528-0.964096 31.506944 1.138688 10.801152 3.98848 22.43072 13.296128 31.737856 31.768576 31.768576 79.8464 45.796864 127.358976 45.796864 47.512064 0 95.5904-14.0288 127.358976-45.796864 9.307136-9.307136 12.15744-20.936704 13.296128-31.737856 1.138688-10.801664 0.360448-21.593088-0.964096-31.506944-0.026112-0.195584-0.05632-0.385536-0.082944-0.580096 48.299008 21.180928 94.98368 51.51488 120.743936 96.805888V791.04H682.496v-135.68h-35.84v135.68H368.128v-135.68h-35.84v135.68H247.296v-192.428032c25.808896-45.376512 72.621056-75.74016 121.016832-96.926208z',
                    }),
                ]
            ),
        ]);
    }
}

const nodeType = NodeTypeEnum.UserTask;
const nodeTypeExtra = nodeType.extra;

export default {
    order: nodeTypeExtra.order,
    type: nodeType.value,
    // 注册配置信息
    registerConf: {
        type: nodeType.value,
        model: UserTaskModel,
        view: UserTaskView,
    },
    dndPanelConf: {
        type: nodeType.value,
        text: nodeTypeExtra.text,
        label: nodeType.label,
        icon: 'data:image/svg+xml;charset=utf-8;base64,PHN2ZyB0PSIxNzQ1ODg4ODY2Mjc1IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjI4OTEiIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiI+PHBhdGggZD0iTTMzNS43NTE2OCAyNDQuNzgzMTA0Yy01Mi4xNDQ2NCAwLTg5LjQ0NzkzNiA0MC4wODYwMTYtODkuNTUyMzg0IDg1Ljc0NjY4OHYwLjAyNTZjMC4wMDMwNzIgMTMuODA4NjQgMy43Mzk2NDggMjguMzgxNjk2IDkuNTc3NDcyIDQxLjUyNjI3MiA0LjIxNTI5NiA5LjQ5MTQ1NiA5LjQ1NTYxNiAxOC4yMTY5NiAxNS44NDEyOCAyNS4yMDY3ODQtMzcuOTUyNTEyIDEyLjk4NDMyLTgyLjQxNjEyOCAzNC4zNTQ2ODgtMTA0Ljg4OTg1NiA3Ni40OTI4bC0xLjIxMTM5MiAyLjI3MTIzMnYxMzYuNDA4NTc2aDM0MC40Njk3NlY0NzYuMDUyNDhsLTEuMjEwODgtMi4yNzA3MmMtMjIuMTUwNjU2LTQxLjUzMjkyOC02NS42NTIyMjQtNjIuODczMDg4LTEwMy4yMzgxNDQtNzUuOTExMTY4IDE4LjM0ODAzMi0xOC42NTgzMDQgMjMuNzYwOD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